package com.woniu.job.entity.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

/**
 * @author sunnylausong
 *  返回结果实体
 * <p>
 * 2019/11/29
 * 21:26
 */
@Data
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class ResultVO<T> {
    private Integer code;
    private Boolean result;
    private String message;
    private T data;

    public ResultVO()
    {
    }

    public <T> ResultVO(int code, boolean result, String message)
    {
        this.code = code;
        this.result = result;
        this.message = message;
    }

    public ResultVO(T data)
    {
        this.code = 200;
        this.result = true;
        this.message = "ok";
        this.data = data;
    }

    /**
     * 快速构建
     */
    public static final ResultVO<?> SUC
            = new ResultVO<>(200, true, "ok");
    public static final ResultVO<?> FORBID
            = new ResultVO<>(403, false, "forbid");
    public static final ResultVO<?> NOTFOUND
            = new ResultVO<>(404, false, "not found");
    public static final ResultVO<?> ERROR
            = new ResultVO<>(500, false, "error");

    public ResultVO code(int code)
    {
        this.code = code;
        return this;
    }

    public ResultVO result(boolean result)
    {
        this.result = result;
        return this;
    }

    public ResultVO message(String message)
    {
        this.message = message;
        return this;
    }

    public ResultVO data(T data)
    {
        this.data = data;
        return this;
    }
}
